<?php
namespace app\testing\controller;

class Index
{   
    public function index()
    {   
        $keyword = $this->request->param('keyword','','trim');
        
        // $businessData = Db::table('pre_business')->select();
        $businessData = Db::name('business')->order('id desc')->select();
        // where('field','value') => WHERE field = value
        // fetchSql() => 查看SQL语句 不是执行SQL
        // $businessData = Db::name('business')->where('mobile','LIKE',"%$keyword%")->order('id desc')->fetchSql(true)->select();
        $businessData = Db::name('business')
                        ->where('mobile','LIKE',"%$keyword%")
                        // ->where('auth',1)
                        // ->whereTime('createtime','between',['2024-1-1','2024-5-25'])
                        ->whereTime('createtime','year')
                        ->order('id desc')
                        ->select();

        // halt($businessData);
        // var_dump($businessData);
        return $this->view->fetch('',['test' => 1,'businessData' => $businessData]);
        // return view();
    }

    public function info()
    {   
        $id = $this->request->param('id',0,'trim');

        // halt($id);
        // $info = Db::name('business')->find($id);
        $info = Db::name('business')->where('id',$id)->find($id);
        
        if(!$info)
        {
            $this->error('用户不存在');
        }
        
        var_dump($info);
    }
}